﻿namespace IP_Package.Operations.Neighbor_operations
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Sharpening class
    /// </summary>
  public class Sharpening : LinearConvolution
    {
        /// <summary>
        /// mask will able it in buffer of image
        /// </summary>
        private Mask mask = new Mask();

        /// <summary>
        /// my Sharpening type
        /// </summary>
        private SharpeningType mySharpening;

        /// <summary>
        /// Sharpening types
        /// </summary>
        public enum SharpeningType
        {
            /// <summary>
            /// point type (Laplacian )
            /// </summary>
            Point,

            /// <summary>
            /// horizontal type in line detection
            /// </summary>
            Horizontal,

            /// <summary>
            /// Vertical type in line detection
            /// </summary>
            Vertical,

            /// <summary>
            /// right diagonal type in line detection
            /// </summary>
            RightDiagonal,

            /// <summary>
            /// left diagonal type in line detection
            /// </summary>
            LeftDiagonal
        }

        /// <summary>
        /// Gets or sets my Sharpening.
        /// </summary>
        /// <value>
        /// My Sharpening.
        /// </value>
        public SharpeningType MySharpening
        {
            get { return this.mySharpening; }
            set { this.mySharpening = value; }
        }

        /// <summary>
        /// Makes the Sharpening.
        /// </summary>
        /// <returns>the new image</returns>
        public Bitmap MakeSharpening()
        {
            this.mask.MaskSize = 3;
            switch (this.mySharpening)
            {
                case SharpeningType.Point:
                    this.mask.MaskValues = new double[,] { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } };
                    break;
                case SharpeningType.Horizontal:
                    this.mask.MaskValues = new double[,] { { 0, 0, 0 }, { 1, 1, -1 }, { 0, 0, 0 } };
                    break;
                case SharpeningType.Vertical:
                    this.mask.MaskValues = new double[,] { { 0, 1, 0 }, { 0, 1, 0 }, { 0, -1, 0 } };                   
                    break;
                case SharpeningType.RightDiagonal:
                    this.mask.MaskValues = new double[,] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 } };
                    break;
                case SharpeningType.LeftDiagonal:
                    this.mask.MaskValues = new double[,] { { 0, 0, 1 }, { 0, 1, 0 }, { -1, 0, 0 } };
                    break;
                default:
                    break;
            }

            try
            {
                return this.LinearConvolutionFn(this.BufferOfImage, this.mask, "Cutoff");
            }
            catch (Exception ex)
            {
                IPPackage.Logger.LogException(ex);
                throw ex;
            }
        }
    }
}
